﻿using System;
using System.Collections.Generic;

namespace Flagwind.Expressions
{
	/// <summary>
	/// 提供词法解析的类。
	/// </summary>
	public class Lexer
	{
		#region 单例字段

		public static readonly Lexer Instance = new Lexer();

		#endregion

		#region 成员字段

		private IList<ITokenizer> _tokenizers;

		#endregion

		#region 构造方法

		public Lexer()
		{
			_tokenizers = new List<ITokenizer>()
			{
				new Tokenization.NullTokenizer(), new Tokenization.NumberTokenizer(), new Tokenization.StringTokenizer(), new Tokenization.BooleanTokenizer(), new Tokenization.IdentifierTokenizer(), new Tokenization.SymbolTokenizer(),
			};
		}

		#endregion

		#region 公共属性

		public IList<ITokenizer> Tokenizers
		{
			get
			{
				return _tokenizers;
			}
		}

		#endregion

		#region 公共方法

		public TokenScanner GetScanner(string text)
		{
			if(string.IsNullOrEmpty(text))
				throw new ArgumentNullException(nameof(text));

			return new TokenScanner(this, text);
		}

		#endregion
	}
}